import { Lv70OpTextTips } from "./operations/Lv70OpTextTips";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { TDrama } from "../../../../Message/Db/Tables/TDrama";
import { DataEvent } from "../../events/DataEvent";
import { EDramaType } from "../../../../Message/Public/EDramaType";
import { Lv70OpControl } from "./operations/Lv70OpControl";
import { Lv70DramaConfig } from "../../resource/Lv70DramaConfig";
import { Cache } from "../../cache/Cache";
import { SSeqPlayerItem } from "../../../../Message/Public/SSeqPlayerItem";
import { TDramaCopy } from "../../../../Message/Db/Tables/TDramaCopy";
import { Lv70OpScreenMove } from "./operations/Lv70OpScreenMove";
import { Lv70OpShowDrama } from "./operations/Lv70OpShowDrama";
import { Lv70OpPlayerMove } from "./operations/Lv70OpPlayerMove";
import { Lv70OpBlackScreen } from "./operations/Lv70OpBlackScreen";
import { Lv70OpNpcTalk } from "./operations/Lv70OpNpcTalk";
import { Lv70OpBlackScreenThenTips } from "./operations/Lv70OpBlackScreenThenTips";
import { Lv70OpShowBonus } from "./operations/Lv70OpShowBonus";
import { Lv70OpPlayEffect } from "./operations/Lv70OpPlayEffect";
import { Lv70OpShowShopEntrace } from "./operations/Lv70OpShowShopEntrace";
import { Lv70OpDownLeftShowText } from "./operations/Lv70OpDownLeftShowText";
import { Lv70OpPetHide } from "./operations/Lv70OpPetHide";
import { Lv70OpFallenLeaves } from "./operations/Lv70OpFallenLeaves";
type int = number;
//class Lv70DramaStepOperator
    
    export  class Lv70DramaStepOperator
    {
        

        public get textTips(): Lv70OpTextTips
        {
            if (this._textTips == null) 
            {
                this._textTips = new Lv70OpTextTips();
            }
            return this._textTips;
        }

        public restart(): void
        {
            Dispatcher.addEventListener(EventName.StageResize, this.stageResizeHandler);
            return;
        }

        public dispose(): void
        {
            Dispatcher.removeEventListener(EventName.StageResize, this.stageResizeHandler);
            if (this._dramaBar != null) 
            {
                this.dramaBar.dispose();
                this._dramaBar = null;
            }
            if (this._blackScreen != null) 
            {
                this._blackScreen.dispose();
                this._blackScreen.dispose();
            }
            if (this._blackThenTips) 
            {
                this._blackThenTips.dispose();
                this._blackThenTips = null;
            }
            if (this._npcTalk != null) 
            {
                this._npcTalk.dispose();
                this._npcTalk = null;
            }
            if (this._roleMove != null) 
            {
                this._roleMove.dispose();
                this._roleMove = null;
            }
            if (this._screenMove != null) 
            {
                this._screenMove.dispose();
                this._screenMove = null;
            }
            if (this._textTips != null) 
            {
                this._textTips.dispose();
                this._textTips = null;
            }
            if (this._bonusView != null) 
            {
                this._bonusView.dispose();
                this._bonusView = null;
            }
            if (this._effectPlayer != null) 
            {
                this._effectPlayer.dispose();
                this._effectPlayer = null;
            }
            if (this._shopEntrace != null) 
            {
                this._shopEntrace.dispose();
                this._shopEntrace = null;
            }
            this.hideBonusView();
            this.hideShopEntrance();
            return;
        }

        /* internal  */stageResizeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.dramaBar.doResizeByStage();
            this.npcTalk.doResizeByStage();
            this.bonusView.middlePlace();
            this.shopEntrance.middlePlace();
            return;
        }

        public operate(arg1: TDrama, arg2: Object=null, arg3: Function=null): void
        {
            var data: TDrama;
            var params: Object=null;
            var callback: Function=null;
            var callEnd: Function;

            var loc1;
            callEnd = null;
            data = arg1;
            params = arg2;
            callback = arg3;
            callEnd = (): void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Lv70DramaStartNextStep, data.step));
                return;
            }
            this._lastStep = data;
            var loc2=data.type;
            switch (loc2) 
            {
                case EDramaType._EDramaNormal:
                {
                    Lv70OpControl.enablePlayerOp = true;
                    Lv70OpControl.enableViews = true;
                    break;
                }
                case EDramaType._EDramaAddDramaTool:
                {
                    this.npcTalk.isKepping = true;
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.dramaBar.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaDelDramaTool:
                {
                    this.npcTalk.isKepping = false;
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.dramaBar.cancel(data, callEnd);
                    break;
                }
                case EDramaType._EDramaPrintDramaText:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.checkAndSetUnKeeping(data);
                    this.npcTalk.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaBlackScreen:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.blackScreen.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaCancleBlackScreen:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.blackScreen.cancel(data, callEnd);
                    break;
                }
                case EDramaType._EDramaPrintInBlackScreen:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.blackThenTips.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaMoveScreen:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.screenMove.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaPlayerMove:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.roleMove.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaRemind:
                {
                    this.textTips.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaShowPanel:
                {
                    Lv70OpControl.enableViews = true;
                    callEnd();
                    break;
                }
                case EDramaType._EDramaHidePanel:
                {
                    Lv70OpControl.enableViews = false;
                    callEnd();
                    break;
                }
                case EDramaType._EDramaSpecialEfficacy:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.effectPlayer.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaRemoveSpecialEfficacy:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.effectPlayer.cancel(data, callEnd);
                    break;
                }
                case EDramaType._EDramaActivePet:
                {
                    this.hidePet.cancel(data, callEnd);
                    break;
                }
                case EDramaType._EDramaDeactivePet:
                {
                    this.hidePet.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaDownLeftText:
                {
                    Lv70OpControl.enablePlayerOp = false;
                    Lv70OpControl.enableViews = false;
                    this.downLeftTalk.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaFallenLeaves:
                {
                    this.fallenLeaves.call(data, callEnd);
                    break;
                }
                case EDramaType._EDramaAddBuff:
                {
                    break;
                }
                case EDramaType._EDramaRemoveBuff:
                {
                    break;
                }
                case EDramaType._EDramaRefreshBoss:
                {
                    break;
                }
                case EDramaType._EDramaRemoveBoss:
                {
                    break;
                }
                case EDramaType._EDramaBossMove:
                {
                    break;
                }
                case EDramaType._EDramaUseSkill:
                {
                    break;
                }
                case EDramaType._EDramaChangeDirection:
                {
                    break;
                }
                case EDramaType._EDramaReward:
                {
                    break;
                }
                case EDramaType._EDramaChangeAi:
                {
                    break;
                }
                case EDramaType._EDramaRefreshShop:
                {
                    break;
                }
            }
            return;
        }

        public enteredDramaCopy(arg1: int=0): void
        {
            var loc1=Lv70DramaConfig.instance.curCopy;
            if (loc1 == null || arg1 == Lv70DramaStepOperator.LockOpAndViews) 
            {
                Lv70OpControl.enablePlayerOp = false;
                Lv70OpControl.enableViews = false;
                return;
            }
            var loc2=Cache.instance.copy.getLv70HightesHistory(loc1.difficulty);
            if (loc2 > loc1.copyCode) 
            {
                Lv70OpControl.enablePlayerOp = false;
                Lv70OpControl.enableViews = false;
            }
            else 
            {
                Lv70OpControl.enablePlayerOp = true;
                Lv70OpControl.enableViews = true;
            }
            return;
        }

        public onDramaAiFinshed(): void
        {
            var onTimer: Function;

            var loc1;
            onTimer = null;
            onTimer = (): void
            {
                roleMove.takeNextRoute();
                return;
            }
            flash.utils.setTimeout(onTimer, 20);
            return;
        }

        public skipDrama(arg1: TDrama): void
        {
            this.npcTalk.isKepping = false;
            this.npcTalk.stopCall();
            this.npcTalk.removeFromStage();
            var loc1=Lv70DramaConfig.instance.getNextLastSkipableDrama(arg1);
            if (loc1 == null) 
            {
                loc1 = arg1;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.Lv70DramaStartNextStep, loc1.step));
            return;
        }

        public showBonus(arg1: SSeqPlayerItem): void
        {
            var data: SSeqPlayerItem;
            var curDrama: TDramaCopy;
            var onGetBonus: Function;

            var loc1;
            onGetBonus = null;
            data = arg1;
            onGetBonus = (): void
            {
                if (_lastStep == null) 
                {
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.Lv70DramaStartNextStep, bonusView.step));
                return;
            }
            Lv70OpControl.enablePlayerOp = true;
            Lv70OpControl.enableViews = true;
            this.bonusView.step = 1;
            curDrama = Lv70DramaConfig.instance.curCopy;
            if (curDrama != null) 
            {
                this.bonusView.step = Lv70DramaConfig.instance.getBonusStep(curDrama.copyCode);
            }
            this.bonusView.show(data, onGetBonus);
            return;
        }

        public hideBonusView(): void
        {
            if (!(this._bonusView == null) && !this._bonusView.isHide()) 
            {
                this._bonusView.hide();
            }
            return;
        }

        public hideShopEntrance(): void
        {
            if (!(this._shopEntrace == null) && !this._shopEntrace.isHide()) 
            {
                this._shopEntrace.hide();
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CloseDramaLotteryModule));
            return;
        }

        public stepSuccess(arg1: int): void
        {
            if (arg1 != this._lastStep.step) 
            {
                return;
            }
            if (this.bonusView.isHide()) 
            {
                return;
            }
            if (arg1 != this.bonusView.step) 
            {
                return;
            }
            this.bonusView.hide();
            return;
        }

        /* internal  */checkAndSetUnKeeping(arg1: TDrama): void
        {
            var loc1=Lv70DramaConfig.instance.getDrama(arg1.copyCode, arg1.step + 1);
            if (loc1.type != EDramaType._EDramaPrintDramaText) 
            {
                this.npcTalk.isKepping = false;
            }
            else 
            {
                this.npcTalk.isKepping = true;
            }
            return;
        }

        public get screenMove(): Lv70OpScreenMove
        {
            if (this._screenMove == null) 
            {
                this._screenMove = new Lv70OpScreenMove();
            }
            return this._screenMove;
        }

        public get dramaBar(): Lv70OpShowDrama
        {
            if (this._dramaBar == null) 
            {
                this._dramaBar = new Lv70OpShowDrama();
            }
            return this._dramaBar;
        }

        public get roleMove(): Lv70OpPlayerMove
        {
            if (this._roleMove == null) 
            {
                this._roleMove = new Lv70OpPlayerMove();
            }
            return this._roleMove;
        }

        public get blackScreen(): Lv70OpBlackScreen
        {
            if (this._blackScreen == null) 
            {
                this._blackScreen = new Lv70OpBlackScreen();
            }
            return this._blackScreen;
        }

        public get npcTalk(): Lv70OpNpcTalk
        {
            if (this._npcTalk == null) 
            {
                this._npcTalk = new Lv70OpNpcTalk();
            }
            return this._npcTalk;
        }

        public get blackThenTips(): Lv70OpBlackScreenThenTips
        {
            if (this._blackThenTips == null) 
            {
                this._blackThenTips = new Lv70OpBlackScreenThenTips();
            }
            return this._blackThenTips;
        }

        public get bonusView(): Lv70OpShowBonus
        {
            if (this._bonusView == null) 
            {
                this._bonusView = new Lv70OpShowBonus();
            }
            return this._bonusView;
        }

        public get effectPlayer(): Lv70OpPlayEffect
        {
            if (this._effectPlayer == null) 
            {
                this._effectPlayer = new Lv70OpPlayEffect();
            }
            return this._effectPlayer;
        }

        public get shopEntrance(): Lv70OpShowShopEntrace
        {
            if (this._shopEntrace == null) 
            {
                this._shopEntrace = new Lv70OpShowShopEntrace();
            }
            return this._shopEntrace;
        }

        public get downLeftTalk(): Lv70OpDownLeftShowText
        {
            if (this._downLeftTalk == null) 
            {
                this._downLeftTalk = new Lv70OpDownLeftShowText();
            }
            return this._downLeftTalk;
        }

        public get hidePet(): Lv70OpPetHide
        {
            if (this._hidePet == null) 
            {
                this._hidePet = new Lv70OpPetHide();
            }
            return this._hidePet;
        }

        public get fallenLeaves(): Lv70OpFallenLeaves
        {
            if (this._fallenLeaves == null) 
            {
                this._fallenLeaves = new Lv70OpFallenLeaves();
            }
            return this._fallenLeaves;
        }

        public static /* const */LockOpAndViews: int=-123455;

        /* internal */ /* var */_lastStep: TDrama;

        /* internal */ /* var */_bonusView: Lv70OpShowBonus;

        /* internal */ /* var */_blackThenTips: Lv70OpBlackScreenThenTips;

        /* internal */ /* var */_effectPlayer: Lv70OpPlayEffect;

        /* internal */ /* var */_roleMove: Lv70OpPlayerMove;

        /* internal */ /* var */_shopEntrace: Lv70OpShowShopEntrace;

        /* internal */ /* var */_blackScreen: Lv70OpBlackScreen;

        /* internal */ /* var */_downLeftTalk: Lv70OpDownLeftShowText;

        /* internal */ /* var */_screenMove: Lv70OpScreenMove;

        /* internal */ /* var */_hidePet: Lv70OpPetHide;

        /* internal */ /* var */_dramaBar: Lv70OpShowDrama;

        /* internal */ /* var */_fallenLeaves: Lv70OpFallenLeaves;

        /* internal */ /* var */_textTips: Lv70OpTextTips;

        /* internal */ /* var */_npcTalk: Lv70OpNpcTalk;
    }
